/*
This file is part of AI Agent Feed.

"AI Agent Feed" is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

"AI Agent Feed" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with "AI Agent Feed".  If not, see <http://www.gnu.org/licenses/>.
 */
package com.feed.services.status;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import org.joda.time.DateTime;
import org.joda.time.Period;

import com.feed.domain.FeedProvider;
import com.feed.domain.FeedStatusCategory;

public class FeedStatus implements Comparable<FeedStatus>, Serializable {
	private static final long serialVersionUID = 1L;
	private Long id;
	private String processor;
	private FeedProvider feedSource;
	private DateTime lastChecked;
	private Period maxInterval;
	private Set<FeedStatusCategory> categories = new HashSet<FeedStatusCategory>();
	private long	scheduledIntervalInMinutes;

	protected FeedStatus() {}

	public FeedStatus(String processor) {
		this.processor = processor;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getProcessor() {
		return processor;
	}

	public void setProcessor(String processor) {
		this.processor = processor;
	}

	public FeedProvider getFeedSource() {
		return feedSource;
	}

	public void setFeedSource(FeedProvider feedSource) {
		this.feedSource = feedSource;
	}

	public DateTime getLastChecked() {
		return lastChecked;
	}

	public void setLastChecked(DateTime lastChecked) {
		this.lastChecked = lastChecked;
	}

	public Period getMaxInterval() {
		return maxInterval;
	}

	public void setMaxInterval(Period maxInterval) {
		this.maxInterval = maxInterval;
	}

	public Set<FeedStatusCategory> getCategories() {
		return categories;
	}

	public void setCategories(Set<FeedStatusCategory> categories) {
		this.categories = categories;
	}

	public long getScheduledIntervalInMinutes() {
		return scheduledIntervalInMinutes;
	}

	public void setScheduledIntervalInMinutes(long scheduledIntervalInMinutes) {
		this.scheduledIntervalInMinutes = scheduledIntervalInMinutes;
	}
	
	 @Override
	    public int hashCode() {
	        final int PRIME = 31;
	        int result = 1;
	        result = PRIME * result + processor.hashCode();
	        return result;
	    }

	    @Override
	    public boolean equals(Object obj) {
	        if (this == obj) {
	            return true;
	        }
	        if (obj == null || !getClass().equals(obj.getClass())) {
	            return false;
	        }

	        final FeedStatus other = (FeedStatus) obj;
	        return processor.equals(other.processor);
	    }

		public int compareTo(FeedStatus other) {
			 int result = feedSource.compareTo(other.feedSource);
		        if (result == 0) {
		            result = processor.compareTo(other.processor);
		        }
		        return result;
		}

}
